//
//  QuDanHomeConfirmOrderController.m
//  QuDanOEM
//
//  Created by mac on 2021/11/8.
#import "QuDanHomeConfirmOrderController.h"
#import "QuDanConfirmHeaderViewCell.h"
#import "QuDanConfirmDestineTimeViewCell.h"
#import "QuDanConfirmStartTimeViewCell.h"
#import "QuDanConfirmOrderTimeViewCell.h"
#import "QuDanConfirmDiscountViewCell.h"
#import "QuDanConfrimPayHeaderViewCell.h"
#import "QuDanConfrimPayTypeViewCell.h"
#import "QuDanConfrimBottomAlterViewCell.h"
#import "QDHomeNetWork.h"
@interface QuDanHomeConfirmOrderController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *totalLab;
@property (weak, nonatomic) IBOutlet UIButton *payBtn;
@property (nonatomic,strong)UICollectionView *confirmOrderCollectionView;
@end
@implementation QuDanHomeConfirmOrderController
- (UICollectionView *)confirmOrderCollectionView
{
    if (!_confirmOrderCollectionView) {
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
        flow.sectionHeadersPinToVisibleBounds = NO;//头视图悬浮
        flow.scrollDirection = UICollectionViewScrollDirectionVertical;
        flow.minimumLineSpacing = 0;//行间距
        flow.minimumInteritemSpacing = 0;//列间距
        _confirmOrderCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flow];
        _confirmOrderCollectionView.backgroundColor =  [UIColor clearColor];
        _confirmOrderCollectionView.showsVerticalScrollIndicator = NO;
        _confirmOrderCollectionView.showsHorizontalScrollIndicator = NO;
        _confirmOrderCollectionView.delegate = self;
        _confirmOrderCollectionView.dataSource = self;
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfirmHeaderViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfirmHeaderViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfirmDestineTimeViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfirmDestineTimeViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfirmStartTimeViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfirmStartTimeViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfirmOrderTimeViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfirmOrderTimeViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfirmDiscountViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfirmDiscountViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfrimPayHeaderViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfrimPayHeaderViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfrimPayTypeViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfrimPayTypeViewCell"];
        [_confirmOrderCollectionView registerNib:[UINib nibWithNibName:@"QuDanConfrimBottomAlterViewCell" bundle:nil] forCellWithReuseIdentifier:@"QuDanConfrimBottomAlterViewCell"];
    }
    return _confirmOrderCollectionView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = QD_RGB(247, 248, 252);
    self.navigationItem.title = @"确认订单";
    self.payBtn.layer.cornerRadius = 20.0f;
    self.payBtn.layer.masksToBounds = YES;
    self.payBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(QD_IPHONE_WIDTH-60, 40) direction:PageGradientChangeDirectionLevel startColor:PostColorP(0xFF5121,1) endColor:PostColorP(0xFFC021,0.5)];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"qd_back"] forState:UIControlStateNormal];
    btn.frame = CGRectMake(0, 0, 40 , 40);
    btn.imageEdgeInsets = UIEdgeInsetsMake(0.0, -15.0, 0.0, 15.0);
    [btn addTarget:self action:@selector(onLeftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem = barItem;
    [self.view addSubview:self.confirmOrderCollectionView];
    [self.confirmOrderCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.offset(0);
    }];
    [self setupConfirmData];
}
/// 会员下单
-(void)setupConfirmData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"publishOrderId"] = self.publishOrderId;
    [[QDHomeNetWork shareInstance]requestHomebuyItOderDetail:param viewController:self andBlock:^(id  _Nullable data, BOOL result) {
        NSLog(@"会员下单data:%@",data);
    }];
}
#pragma mark --- UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 3;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if(section == 1){
        return 4;
    }else{
        return 3;
    }
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        QuDanConfirmHeaderViewCell *headerCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfirmHeaderViewCell" forIndexPath:indexPath];
        return headerCell;
    }else if(indexPath.section == 1){
        if (indexPath.row == 0) {
            QuDanConfirmDestineTimeViewCell *destineTimeCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfirmDestineTimeViewCell" forIndexPath:indexPath];
            return destineTimeCell;
        }else if(indexPath.row == 1){
            QuDanConfirmStartTimeViewCell *startTimeCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfirmStartTimeViewCell" forIndexPath:indexPath];
            return startTimeCell;
        }else if(indexPath.row == 2){
            QuDanConfirmOrderTimeViewCell *orderCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfirmOrderTimeViewCell" forIndexPath:indexPath];
            return orderCell;
        }else{
            QuDanConfirmDiscountViewCell *discountCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfirmDiscountViewCell" forIndexPath:indexPath];
            return discountCell;
        }
    }else{
        if (indexPath.row == 0) {
            QuDanConfrimPayHeaderViewCell *headerCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfrimPayHeaderViewCell" forIndexPath:indexPath];
            return headerCell;
        }else if(indexPath.row == 1){
            QuDanConfrimPayTypeViewCell *payCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfrimPayTypeViewCell" forIndexPath:indexPath];
            return payCell;
        }else{
            QuDanConfrimBottomAlterViewCell *bottomAlterCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuDanConfrimBottomAlterViewCell" forIndexPath:indexPath];
            return bottomAlterCell;
        }
    }
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (section == 0) {
        return UIEdgeInsetsMake(1, 0, 0, 0);
    }else  if (section == 1) {
        return UIEdgeInsetsMake(5, 0, 0, 0);
    }else{
        return UIEdgeInsetsMake(5, 0, 0, 0);
    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return CGSizeMake(QD_IPHONE_WIDTH ,65);
    }else if(indexPath.section == 1){
        if (indexPath.row == 0) {
            return CGSizeMake(QD_IPHONE_WIDTH ,130);
        }else if(indexPath.row == 1){
            return CGSizeMake(QD_IPHONE_WIDTH ,60);
        }else if(indexPath.row == 2){
            return CGSizeMake(QD_IPHONE_WIDTH ,60);
        }else{
            return CGSizeMake(QD_IPHONE_WIDTH ,60);
        }
    }else{
        if (indexPath.row == 0) {
            return  CGSizeMake(QD_IPHONE_WIDTH ,50);
        }else if(indexPath.row == 1){
            return CGSizeMake(QD_IPHONE_WIDTH ,150);
        }else{
            return CGSizeMake(QD_IPHONE_WIDTH ,60);;
        }
    }
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
}
-(void)onLeftBtnAction:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
